/**
 * 
 */
package com.thon.controller.util;

import java.util.Properties;

import javax.mail.internet.MimeMessage;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;

/**
 * @author THON
 * @email thon.ju@meet-future.com
 * @date 2011-11-26 下午10:53:39
 * @description:
 */
public class SingleMailSend {
	public static void main(String args[]) {
		JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
		
		// 设定mail server
		senderImpl.setHost("smtp.exmail.qq.com");
		senderImpl.setPort(25);
		senderImpl.setUsername("service@jishanjia.com"); // 根据自己的情况,设置username
		senderImpl.setPassword("q602535@"); // 根据自己的情况, 设置password
		Properties prop = new Properties();
		prop.put("mail.smtp.auth", " true"); // 将这个参数设为true，让服务器进行认证,认证用户名和密码是否正确
		prop.put("mail.smtp.timeout", "25000");
		senderImpl.setJavaMailProperties(prop);

		// 建立邮件消息
		SimpleMailMessage mailMessage = new SimpleMailMessage();
		String[] array = new String[] { "juxuejian@163.com" };
		mailMessage.setTo(array);
		mailMessage.setFrom("service@jishanjia.com");
		mailMessage.setSubject("[JiShan]");
		mailMessage.setText(" 测试我的简单邮件发送机制！！ ");
		
		MimeMessagePreparator preparator = new MimeMessagePreparator(){
			public void prepare(MimeMessage mimeMessage) throws Exception {
				MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
				helper.setFrom("service@jishanjia.com");
				helper.setSubject("[积善之家]恭喜您注册成功，请根据邮件激活帐号");
				helper.setText(" 测试我的简单邮件发送机制！！ ", true);
				helper.addTo("juxuejian@163.com");
			}
		};
		
		
		// 发送简单邮件
		//senderImpl.send(mailMessage);
		
		// 发送复杂邮件
		senderImpl.send(preparator);

	}
}
